<?php 
/**
 * Description of form
 * @author diotheos
 * @since 7 мая 2010
 */
class App_Form_User_Login extends Lib_Form_Clear{
	/**
	 * Initialization of form function
	 * 
	 * @since 7 мая 2010
	 * @author diotheos
	 * @return Zend_Form
	 */
	public function init(){
		parent::init();
		
		$this->setMethod('post');
        $this->setAction('');
        
        $email = new Zend_Form_Element_Text('email');
        
        $email->setRequired()
              ->setLabel(_('Мой Email'))
              ->setFilters(array(
                    'StringToLower',
                    'StringTrim'
              ))
              ->addValidators(array(
                    array('NotEmpty', true),
                    array('stringLength', false, array(6,40)),
                    new Zend_Validate_EmailAddress(
                        Zend_Validate_Hostname::ALLOW_DNS,
                        true
                    ),
                    new Lib_Form_Validate_DbHasRecord('Automoto\User','email')
              ));
        $email->addErrorMessage(_('Введите правильный email и пароль'));      
        $this->addElement($email);

        $password = new Zend_Form_Element_Password('password');
        $password->setLabel(_('Мой пароль'))
                 ->setRequired()
                 ->addValidators(array(
                     array('NotEmpty', true),
                     array('stringLength', false, array(6,12)),                    
                 ));
        $password->addErrorMessage(_('Введите правильный email и пароль'));         
        $this->addElement($password);
        
        $submit = new Zend_Form_Element_Submit('signin');
        $submit->setLabel(_('Войти'));
        $submit->clearDecorators();
        $submit->addDecorator('ViewHelper');
        $this->addElement($submit);
		$this->setDecorators(array(
            array('ViewScript', array('viewScript'=>'forms/user/login.phtml', 'class'=> 'form element'))
        ));
		return $this;
	}
}